import 'package:flutter/material.dart';
import 'package:dio/dio.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Button',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyPage(),
    );
  }
}

class MyPage extends StatefulWidget {
  @override
  _MyPageState createState() => _MyPageState();
}

class _MyPageState extends State<MyPage> {
  String _data = "";
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: <Widget>[
          Container(
            margin: EdgeInsets.only(top:100),
            child: FlatButton(onPressed: () async{
              Dio dio = new Dio();
              //get传参
              Response res = await dio.get("https://www.baidu.com",queryParameters: {"username":"lizhiwei"});
              //post传参
              dio.post("https://www.baidu.com",data: {"username":"lizhiwei"});
              //下载文件
              //dio.download(urlPath, savePath);
              print("result:"+ res.data.toString());
              setState(() {
                _data = res.data.toString();
              });
            }, child: Text("发起http请求"),
              color: Colors.red,

            ),
          ),
          Scrollbar(
            child: Container(
              height: 400,
              child: SingleChildScrollView(
                child: Text(_data),
              ),
            ),
          ),

        ],
      ),
    );
  }
}
